package jsen.tool.ddd.adapter.infrastructure.specification.demo;

import jsen.tool.ddd.adapter.infrastructure.specification.ISpecification;
import jsen.tool.ddd.adapter.infrastructure.specification.base.SpecContext;
import jsen.tool.ddd.adapter.infrastructure.specification.demo.spec.line.LineSpecFactory;
import jsen.tool.ddd.adapter.infrastructure.specification.demo.spec.send.SendMethodSpecFactory;
import jsen.tool.ddd.adapter.infrastructure.specification.demo.spec.simple.SimpleSpecFactory;

/**
 * @author jsen
 * @date 2021/10/6
 */
public class Test {
    public static void main(String[] args) {
        String sdl = "s1 or s2";
        ISpecification<String> specification = SimpleSpecFactory.buildSpec(sdl);
        assert specification.isSatisfiedBy(SpecContext.create("jsen"));


        sdl = "s1 and s2";
        specification = SimpleSpecFactory.buildSpec(sdl);
        assert !specification.isSatisfiedBy(SpecContext.create("jsen"));


        sdl = "(((s1 and s2) or s3) and s4) or s5";
        specification = SimpleSpecFactory.buildSpec(sdl);
        assert specification.isSatisfiedBy(SpecContext.create("jsen"));


        SendMethod info = SendMethod.builder().name("jsen").alias("jsen").type(1).age(0)
                .strict(SendMethodSpecFactory.buildSpec()).line(
                        Line.builder().width(99).strict(LineSpecFactory.buildSpec()).build()
                ).build();
        SpecContext<SendMethod> specContext = info.strict(null);
        assert !specContext.isValid();


        info = SendMethod.builder().name("jsen").alias("jack").type(1).age(1)
                .strict(SendMethodSpecFactory.buildSpec()).line(
                        Line.builder().width(100).strict(LineSpecFactory.buildSpec()).build()
                ).build();
        specContext = info.strict(null);
        assert specContext.isValid();
    }
}
